package app.netant.book.janpn;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class JanPnDetail extends BaseDetail {

	public JanPnDetail(String netSite) {
		super(netSite);
		this.preHref = "http://huijinjinian.janpn.com/";
	}

	@Override
	public void analyseTitle() {
		
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select("body .container .row.movie .info p");
		for(int i=0;i<parts.size();i++){
			
			String childs = parts.get(i).text();
			
			if(childs.indexOf("[小说作者]:")>0){
				int idx = childs.indexOf("[小说作者]:");
				String tagValue = childs.substring(idx+7);				
				System.out.println("【Writer】:"+tagValue);
				this.entity.setNovelWriter(tagValue);
			}
			else if(childs.indexOf("[更新时间]:")>0){
				int idx = childs.indexOf("[更新时间]:");
				String tagValue = childs.substring(idx+7);
				System.out.println("【Date】:"+tagValue);
				this.entity.setNovelDate(tagValue);
			}
			else if(childs.indexOf("[小说简介]:")>0){
				int idx = childs.indexOf("[小说简介]:");
				String tagValue = childs.substring(idx+7);
				System.out.println("【Memo】:"+tagValue);
				this.entity.setNovelMemo(tagValue);
			}
			
		}
	}

	@Override
	public void analyseMemo() {
		
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("body .container .info .ptb10 .text-center a.btn-block.btn");
		if(parts.size()>0){
			String click = parts.get(0).attr("onclick");
			int st = click.indexOf("http://");
			int ed = click.indexOf("','_self')");
			String href = click.substring(st,ed);
			System.out.println("【Href】:"+href);
			this.entity.setDownPath(href);
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select("body .container h3");
		if(parts.size()>0){
			String title = parts.get(0).text();
			int idx = title.indexOf("：");
			if(idx>0){
				String type = title.substring(0,idx);
				String name = title.substring(idx+1);
				
				if(type.length()>4){
					type = type.substring(0,4);
				}
				
				int st = name.indexOf("《");
				int ed = name.indexOf("》");
				
				if(st>=0 && ed>=0 && ed>st){
					name = name.substring(st+1,ed);
				}
				
				System.out.println("【Type】:"+type);
				System.out.println("【Title】:"+name);
				
				this.entity.setNovelType(type);
				this.entity.setNovelName(name);
				this.entity.setNovelFullName(name+".txt");
				
			}
		}
	}
	
	public static void main(String[] args) {
		JanPnDetail detail = new JanPnDetail("http://bingbushichuanyuedecaozuojing.janpn.com/");
		detail.test();
	}



}
